home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-27 | 5.6 KB | 230 lines | [TEXT/CWIE] |
- //
- // CPropPane.cp
- //
- // class CPropPane
- // A Pane for rendering 4 boxes in a QuickDraw 3D view.
- // Borrowed heavily from the "START HERE" sample code from Apple.
- //
- // by James Jennings
- // November 22, 1995
- //
-
- #include "CPropPane.h"
- #include "C3Lights.h" // defines the light group
- #include "CCameraMaker.h" // defines the camera
- #include "CBoxMaker.h"
- #include "CClubMaker.h"
- #include "StQ3Disposer.h"
- #include "QD3D Debug Macros.h"
-
- //const CommandT cmd_NewPropPane = 1200; // used in CJuggleApp
- const CommandT cmd_Jitterbug = 1201;
- const CommandT cmd_CubeProp = 1202;
- const CommandT cmd_ClubProp = 1203;
-
- CPropPane*
- CPropPane::CreatePropPaneStream(LStream *inStream)
- {
- return new CPropPane(inStream);
- }
-
- CPropPane::CPropPane() : mPropType(prop_Cube), mJitterbug(false)
- { // default constructor
- // Does nothing. Must call FinishCreate() later.
- }
-
- CPropPane::CPropPane(const CPropPane &inOriginal)
- : CQD3DGimbalPane(inOriginal), mCube(inOriginal.mCube), mClub(inOriginal.mClub),
- mPropType(prop_Cube), mJitterbug(false)
- { // copy constructor
- StartIdling(); // start the periodical
- }
-
- CPropPane::CPropPane(LStream *inStream)
- : CQD3DGimbalPane(inStream), mPropType(prop_Cube), mJitterbug(false)
- { // stream constructor
- // Does nothing. Must call FinishCreate() later.
- }
-
- CPropPane::~CPropPane()
- { // destructor
- }
-
- void
- CPropPane::FinishCreateSelf()
- { // Inherit the other initialization.
- CQD3DGimbalPane::FinishCreateSelf();
-
- StartIdling(); // start the periodical
- }
-
- void
- CPropPane::MakeCamera()
- { // Make and add a camera to the current view.
- SDimension16 frameSize;
- GetFrameSize(frameSize);
- CCameraMaker theCamera(frameSize); // construct a camera
- // Change the default position
- theCamera.SetLocation(0,7,0);
- theCamera.SetUpVector(0,0,1);
- TQ3Status status = ::Q3View_SetCamera(mView, theCamera.Get());
- ThrowIfQ3Fail_(status);
- }
-
- void
- CPropPane::MakeLightGroup()
- {
- C3Lights theLights;
- // add the lights to the group
- TQ3Status status = ::Q3View_SetLightGroup(mView, theLights.Get());
- ThrowIfQ3Fail_(status);
- }
-
- void
- CPropPane::MakeModel()
- {
- // construct the model(s)
- TQ3Point3D origin = { 0.5, 0.5, 0.5};
- mCube.MakeModel(CBoxMaker(), origin);
- ::Q3Point3D_Set(&origin, 0.0, 0.0, 1.4);
- mClub.MakeModel(CClubMaker(), origin);
- // Note: We aren't using the member CQD3DPane::mModel
- }
-
- TQ3Status
- CPropPane::SubmitScene()
- { // Submit the stuff we have in our scene.
- TQ3Status status;
- status = ::Q3Style_Submit( mInterpolation, mView );
- if (status==kQ3Failure) return status;
- status = ::Q3Style_Submit( mBackFacing, mView );
- if (status==kQ3Failure) return status;
- status = ::Q3Style_Submit( mFillStyle, mView );
- if (status==kQ3Failure) return status;
- switch (mPropType) {
- case prop_Club:
- status = ::Q3DisplayGroup_Submit( mClub.Get(), mView );
- break;
- case prop_Cube:
- default:
- status = ::Q3DisplayGroup_Submit( mCube.Get(), mView );
- break;
- }
- return status;
- }
-
- void
- CPropPane::SpendTime( const EventRecord &inMacEvent)
- { // on each null event, spin a little.
- CProp *theProp;
- switch (mPropType) {
- case prop_Club: theProp = &mClub; break;
- case prop_Cube:
- default: theProp = &mCube; break;
- }
- // Set the angle to spin at 90 degrees / second
- float angle = ((float)TickCount()) * kQ3Pi / 120;
- // theProp->SetSpinAngle(angle);
- theProp->SetSpinAngle(angle*3); // temporary: speed it up a little
-
- // move the cube about on a sphere
- TQ3SphericalPoint sPt;
- TQ3Point3D a, b;
- ::Q3Point3D_Set(&a, 2.0, 0, 0);
- if (mJitterbug) {
- float theta = angle/5;
- b.x = a.x*cos(theta) - a.y*sin(theta);
- b.y = a.x*sin(theta) + a.y*cos(theta);
- b.z = a.z;
- float phi = angle/1.41;
- a.z = b.z*cos(phi) - b.y*sin(phi);
- a.y = b.z*sin(phi) + b.y*cos(phi);
- a.x = b.x;
- }
- theProp->SetPosition(a);
-
- // give it a 23 deg wobble
- const float wobbleSize = 23*kQ3Pi/180;
- theProp->SetTiltAngle( wobbleSize * sin(angle/3) );
-
- // If this is a null event, Refresh().
- // Otherwise, we're in a click-drag loop, and we don't.
- if (inMacEvent.what==nullEvent)
- Refresh();
- }
-
- Boolean
- CPropPane::ClickLoop( const EventRecord &inMacEvent )
- { // subclasses may override to modify the scene in some other way
- SpendTime(inMacEvent);
- return true;
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- CPropPane::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
- case cmd_Jitterbug:
- mJitterbug = ! mJitterbug;
- break;
- case cmd_CubeProp:
- mPropType = prop_Cube;
- break;
- case cmd_ClubProp:
- mPropType = prop_Club;
- break;
- default:
- cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- CPropPane::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
- case cmd_Jitterbug:
- outEnabled = true;
- outUsesMark = true;
- outMark = (mJitterbug)? checkMark : noMark;
- break;
- case cmd_CubeProp:
- outEnabled = true;
- outUsesMark = true;
- outMark = (mPropType==prop_Cube)? checkMark : noMark;
- break;
- case cmd_ClubProp:
- outEnabled = true;
- outUsesMark = true;
- outMark = (mPropType==prop_Club)? checkMark : noMark;
- break;
- default:
- LCommander::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-